package com.xqboss.apps.enums.order;


import com.xqboss.common.enums.BaseEnum;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 订单状态
 */
public enum OutOrderStatusEnum implements BaseEnum<Integer> {
    UN_PAY(0, "未付款"),
    PAYED(1, "已付款"),
    CANCEL(2, "已取消"),
    REFUND(3, "已退款"),
    ;

    private final Integer value;
    private final String msg;

    OutOrderStatusEnum(Integer value, String description) {
        this.value = value;
        this.msg = description;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public String getMsg() {
        return msg;
    }


    public static List<OrderStatusEnum> toOrderStatus(OutOrderStatusEnum appOrderStatus){
        switch (appOrderStatus){
            case UN_PAY:
                return Collections.singletonList(OrderStatusEnum.UN_PAY);
            case PAYED:
                return Arrays.asList(OrderStatusEnum.PAYED, OrderStatusEnum.COMPLETED);
            case CANCEL:
                return Arrays.asList(OrderStatusEnum.CANCEL, OrderStatusEnum.CLOSE);
            case REFUND:
                return Collections.singletonList(OrderStatusEnum.REFUND);
        }
        return Collections.emptyList();
    }

    public static OutOrderStatusEnum toOrderStatus(OrderStatusEnum orderStatus){
        if(orderStatus != null){
            switch (orderStatus) {
                case UN_PAY:
                    return OutOrderStatusEnum.UN_PAY;
                case PAYED:
                case COMPLETED:
                    return OutOrderStatusEnum.PAYED;
                case REFUND:
                    return OutOrderStatusEnum.REFUND;
                case CLOSE:
                    return OutOrderStatusEnum.CANCEL;
                case CANCEL:
                    return OutOrderStatusEnum.CANCEL;
            }
        }
        return null;
    }
}
